"""
    create by IAmFiveHigh on 2024/5/23
"""
from LA.__globals import is_zero
from LA.GramSchmidtProcess import gram_schmidt_process
from LA.Vector import Vector


def schmidt_process(basis):
    print("-" * 5, "原向量组", "-" * 5)
    for v in basis:
        print(v)
    res = gram_schmidt_process(basis)
    print("-" * 5, "正交基", "-" * 5)
    for row in res:
        print(row)
    print("-" * 5, "标准正交基", "-" * 5)
    res = [row / row.norm() for row in res]
    for row in res:
        print(row)
    print("-" * 5, "验证", "-" * 5)
    print(f"{res[0]}.dot {res[-1]}  { '== 0' if is_zero(res[0].dot(res[-1])) else '!= 0'}")
    print("\n")


if __name__ == '__main__':
    basis1 = [Vector([2, 1]), Vector([1, 1])]
    schmidt_process(basis1)

    basis2 = [Vector([1, 1, 5, 2]), Vector([-3, 3, 4, -2]), Vector([-1, -2, 2, 5])]
    schmidt_process(basis2)